const express=require('express')
const cors=require('cors')
const uuid=require('uuid')
const multer=require('multer')

let upload=multer({
	storage:multer.diskStorage({
		destination:'upload',
		filename(req,file,callback){
			let fn=file.originalname
			let ext=fn.substring(fn.lastIndexOf('.'))
			callback(null,uuid.v4()+ext)
		}
	})
})
const app=express()
app.listen(9000,()=>{
	console.log('9000端口上传启动')
})
app.use(cors())
app.use(express.static('upload'))
// 单文件上传
app.post('/upload',upload.single('avatar'),(req,res)=>{
	res.send(req.file)
})
// 多文件上传
app.post('/uploadmul',upload.array('duo'),(req,res)=>{
	res.send(req.files)
})
